package com.stoneframe.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stoneframe.activeMQ.QueueSender;
import com.stoneframe.activeMQ.TopicSender;

//@Controller
//@RequestMapping(value="activemq")
public class ActivemqController {
	
	@Resource(name="queueSender")
	private QueueSender queueSender;
	
	@Resource(name="topicSender")
	private TopicSender topicSender;
	
	/**
     * 发送消息到队列
     * @param message
     * @return String
     */
	@RequestMapping(value="queueSender")
	@ResponseBody
	public String queueSender(@RequestParam("message") String message){
		String opt="";
		try{
			queueSender.send("spring.queue", message);
			opt="suc";
		}catch(Exception e){
			opt=e.getCause().toString();
		}
		return opt;
	}
	
	/**
     * 发送消息到主题
     * @param message
     * @return String
     */
	@RequestMapping(value="topicSender")
	@ResponseBody
	public String topicSender(@RequestParam("message")String message){
		String opt="";
		try{
			topicSender.send("spring.topic", message);
			opt="suc";
		}catch(Exception e){
			opt=e.getCause().toString();
		}
		return opt;
	}

}
